package cn.iocoder.yudao.module.bpm.controller.admin.overdue;

import cn.iocoder.yudao.module.bpm.controller.admin.overdue.vo.OverdueReminderLogPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.overdue.vo.OverdueReminderLogRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.overdue.vo.OverdueReminderLogSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.overdue.OverdueReminderLogDO;
import cn.iocoder.yudao.module.bpm.service.overdue.OverdueReminderLogService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;



@Tag(name = "管理后台 - 流程逾期提醒记录")
@RestController
@RequestMapping("/bpm/overdue-reminder-log")
@Validated
public class OverdueReminderLogController {

    @Resource
    private OverdueReminderLogService overdueReminderLogService;

    @PostMapping("/create")
    @Operation(summary = "创建流程逾期提醒记录")
    @PreAuthorize("@ss.hasPermission('bpm:overdue-reminder-log:create')")
    public CommonResult<Long> createOverdueReminderLog(@Valid @RequestBody OverdueReminderLogSaveReqVO createReqVO) {
        return success(overdueReminderLogService.createOverdueReminderLog(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新流程逾期提醒记录")
    @PreAuthorize("@ss.hasPermission('bpm:overdue-reminder-log:update')")
    public CommonResult<Boolean> updateOverdueReminderLog(@Valid @RequestBody OverdueReminderLogSaveReqVO updateReqVO) {
        overdueReminderLogService.updateOverdueReminderLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除流程逾期提醒记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('bpm:overdue-reminder-log:delete')")
    public CommonResult<Boolean> deleteOverdueReminderLog(@RequestParam("id") Long id) {
        overdueReminderLogService.deleteOverdueReminderLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得流程逾期提醒记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('bpm:overdue-reminder-log:query')")
    public CommonResult<OverdueReminderLogRespVO> getOverdueReminderLog(@RequestParam("id") Long id) {
        OverdueReminderLogDO overdueReminderLog = overdueReminderLogService.getOverdueReminderLog(id);
        return success(BeanUtils.toBean(overdueReminderLog, OverdueReminderLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得流程逾期提醒记录分页")
    @PreAuthorize("@ss.hasPermission('bpm:overdue-reminder-log:query')")
    public CommonResult<PageResult<OverdueReminderLogRespVO>> getOverdueReminderLogPage(@Valid OverdueReminderLogPageReqVO pageReqVO) {
        PageResult<OverdueReminderLogDO> pageResult = overdueReminderLogService.getOverdueReminderLogPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, OverdueReminderLogRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出流程逾期提醒记录 Excel")
    @PreAuthorize("@ss.hasPermission('bpm:overdue-reminder-log:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportOverdueReminderLogExcel(@Valid OverdueReminderLogPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<OverdueReminderLogDO> list = overdueReminderLogService.getOverdueReminderLogPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "流程逾期提醒记录.xls", "数据", OverdueReminderLogRespVO.class,
                        BeanUtils.toBean(list, OverdueReminderLogRespVO.class));
    }

}